var arr1 = [10, 2, 5, 3, 8, 9, 6, 556, 96, 199]
//console.log('arr', arr)
//for (let i = 0; i < arr.length - 1; i++) { 
//    console.log('-------',i)
//    for (let j = 0; j < arr.length - 1 - i; j++) { 
//        if (arr[j] > arr[j + 1]) { 
//            //console.log('arr[j]0', arr[j], arr[j + 1])
//            let temp = arr[j]
//            arr[j] = arr[j + 1]
//            arr[j + 1] = temp
//            //console.log('arr[j]1', arr[j], arr[j + 1])
//        }
//    }
//    console.log(arr)
//}
//console.log(arr)



function bubble(arr) {
	if (!(arr instanceof Array) || !arr.length) throw new TypeError('arr must be a Array!');
	for (var i = 0; i < arr.length; i++) {
		for (var j = 0; j < arr.length - i; j++) {
			if (arr[j] > arr[j + 1]) {
				//var temp = arr[j];
				//arr[j] = arr[j + 1];
				//arr[j + 1] = temp;
				//console.log('s', [arr[j + 1], arr[j]])
				[arr[j + 1], arr[j]] = [arr[j], arr[j + 1]]
				console.log('arr', arr)
			}
		}
	}
	return arr
}
//依次交换位置
console.log(bubble(arr1))